#ifndef __LINUXOS__H__
#define __LINUXOS__H__

#include "core.h"
#include "fileutils.h"
#include "stringutils.h"
#include "commandutils.h"
#include "logs/log.h"

// ┌──────────────────────────────────────────────────────────────────────────────┐
// │ /etc/network/interface.d                                                     │
// └──────────────────────────────────────────────────────────────────────────────┘
#define LINUX_OS_NETWORK_INTERFACE          "/etc/network/interfaces"
// /etc/network/interfaces.d/ipv4/*
#define LINUX_OS_NETWORK_INTERFACE_APN      "/etc/network/interfaces.d/ipv4/apn"
#define LINUX_OS_NETWORK_INTERFACE_BRIDGE   "/etc/network/interfaces.d/ipv4/bridge"
#define LINUX_OS_NETWORK_INTERFACE_DHCP     "/etc/network/interfaces.d/ipv4/dhcp"
#define LINUX_OS_NETWORK_INTERFACE_FREQLOCK "/etc/network/interfaces.d/ipv4/freqlock"
#define LINUX_OS_NETWORK_INTERFACE_NTP      "/etc/network/interfaces.d/ipv4/ntp"
#define LINUX_OS_NETWORK_INTERFACE_WWAN     "/etc/network/interfaces.d/ipv4/wwan"
#define LINUX_OS_NETWORK_INTERFACE_LAN      "/etc/network/interfaces.d/ipv4/lan"
#define LINUX_OS_NETWORK_INTERFACE_WAN      "/etc/network/interfaces.d/ipv4/wan"
#define LINUX_OS_NETWORK_INTERFACE_WLAN     "/etc/network/interfaces.d/ipv4/wlan"

// e.g:
//  iface ntp conf ntp
//  iface hostapd conf hostapd
//  iface eth0 inet dhcp
//  iface eth1 inet manual

// syntax:
// iface <iface> <conf|[inet|inet6]> <[dhcp|static|manual]|...>

// ------------------------------------ CONFIG_TYPE <conf|[inet|inet6]>
#define LINUX_OS_INTERFACE_CONF_TYPE_DEFINE(conf) #conf
// conf
#define LINUX_OS_INTERFACE_CONF_TYPE_CONF       \
    LINUX_OS_INTERFACE_CONF_TYPE_DEFINE(conf)
// ipv4/ipv6
#define LINUX_OS_INTERFACE_CONF_TYPE_IPV4       \
    LINUX_OS_INTERFACE_CONF_TYPE_DEFINE(inet)
#define LINUX_OS_INTERFACE_CONF_TYPE_IPV6       \
    LINUX_OS_INTERFACE_CONF_TYPE_DEFINE(inet6)

// ------------------------------------ WORK_TYPE <[dhcp|static|manual]|...>
#define LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(work) #work
// auto
#define LINUX_OS_INTERFACE_WORK_TYPE_AUTO       \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(auto)
// dhcp
#define LINUX_OS_INTERFACE_WORK_TYPE_DHCP       \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(dhcp)
// static
#define LINUX_OS_INTERFACE_WORK_TYPE_STATIC     \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(static)
// manual
#define LINUX_OS_INTERFACE_WORK_TYPE_MANUAL     \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(manual)
// conf
#define LINUX_OS_INTERFACE_WORK_TYPE_CONF       \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(conf)
// hostapd
#define LINUX_OS_INTERFACE_WORK_TYPE_HOSTAPD    \
    LINUX_OS_INTERFACE_WORK_TYPE_DEFINE(hostapd)
// LINUX_OS_INTERFACE_WORK_TYPE_CONF(conf)      -> "conf"

// ------------------------------------ Interface Props
#define LINUX_OS_NET_IFACE_PROP_DEFINE(prop)    #prop
// router
#define LINUX_OS_NET_IFACE_PROP_ROUTER          \
    LINUX_OS_NET_IFACE_PROP_DEFINE(router)
// address
#define LINUX_OS_NET_IFACE_PROP_ADDRESS         \
    LINUX_OS_NET_IFACE_PROP_DEFINE(address)
// netmask
#define LINUX_OS_NET_IFACE_PROP_NETMASK         \
    LINUX_OS_NET_IFACE_PROP_DEFINE(netmask)
// gateway
#define LINUX_OS_NET_IFACE_PROP_GATEWAY         \
    LINUX_OS_NET_IFACE_PROP_DEFINE(gateway)
// interface
#define LINUX_OS_NET_IFACE_PROP_INTERFACE       \
    LINUX_OS_NET_IFACE_PROP_DEFINE(interface)
// nameserver
#define LINUX_OS_NET_IFACE_PROP_NAMESERVER      \
    LINUX_OS_NET_IFACE_PROP_DEFINE(nameserver)
// dns-nameserver
#define LINUX_OS_NET_IFACE_PROP_DNS_NAMESERVER  \
    LINUX_OS_NET_IFACE_PROP_DEFINE(dns-nameserver)

// ┌──────────────────────────────────────────────────────────────────────────────┐
// │ /etc/os-release                                                              │
// └──────────────────────────────────────────────────────────────────────────────┘
#define LINUX_OS_RELEASE_CONFIG "/etc/os-release"

// ┌──────────────────────────────────────────────────────────────────────────────┐
// │ /proc                                                                        │
// └──────────────────────────────────────────────────────────────────────────────┘
#define LINUX_OS_PROC_CMDLINE   "/proc/cmdline"
#define LINUX_OS_PROC_MEMINFO   "/proc/meminfo"
#define LINUX_OS_PROC_UPTIME    "/proc/uptime"
#define LINUX_OS_PROC_LOADAVG   "/proc/loadavg"

// ┌──────────────────────────────────────────────────────────────────────────────┐
// │ /proc/self                                                                   │
// └──────────────────────────────────────────────────────────────────────────────┘
#define LINUX_OS_PROC_SELF_STATUS "/proc/self/status"

// /proc/net/*
#define LINUX_OS_PROC_NET_APR "/proc/net/arp"
#define LINUX_OS_PROC_NET_DEV "/proc/net/dev"

// 构造结构体信息
typedef void(*Linux_Define_Object);
#define Linux_Define_Object(obj)               \
typedef struct _##obj obj;                     \
struct _##obj

#define Linux_Define_Object_Size_Define(obj) int obj##Size();
#define Linux_Define_Object_Create_Define(obj) obj* create##obj();
#define Linux_Define_Object_Size(obj) int obj##Size(){return sizeof(struct _##obj);}
#define Linux_Define_Object_Create(obj) obj* create##obj(){return (obj*)calloc(obj##Size(), 1);}

#endif  //!__LINUXOS__H__